<?php
	require_once($GLOBALS['BIB'].'Pr_db/pr_historics.mex');
	$RegID = 0;
	if ($_POST['smb_DocID'] == '') { $_POST['smb_DocID'] = 0; }
	
	if ($_POST['smb_ID'] == 0) {
		$PID = 390;
		if($GLOBALS['MYT']->db_query("INSERT INTO systemoffice.staff_members (smb_Name,smb_CODE,smb_Birthdate,smb_AdmissionDate,smb_CttEmail,smb_CttPhone,smb_CttExtention,smb_Domain,smb_CttAddress,smb_DocID,smb_DocNumber,smb_SSID,smb_Nacionalidade,smb_Civil,smb_Dependentes,smb_Habilitacoes,smb_ContractType,smb_Wage,smb_DocDate,smb_DocValid,smb_DocReceived,smb_DocLocal,smb_NIF,smb_AdmissionMotive,smb_Function)
				VALUES
('{$_POST['smb_Name']}',{$_POST['smb_CODE']},'{$_POST['smb_Birthdate']}','{$_POST['smb_AdmissionDate']}','{$_POST['smb_CttEmail']}','{$_POST['smb_CttPhone']}','{$_POST['smb_CttExtention']}',{$_POST['smb_Domain']},'{$_POST['smb_CttAddress']}',{$_POST['smb_DocID']},'{$_POST['smb_DocNumber']}','{$_POST['smb_SSID']}','{$_POST['smb_Nacionalidade']}','{$_POST['smb_Civil']}','{$_POST['smb_Dependentes']}','{$_POST['smb_Habilitacoes']}','{$_POST['smb_ContractType']}','{$_POST['smb_Wage']}','{$_POST['smb_DocDate']}','{$_POST['smb_DocValid']}','{$_POST['smb_DocReceived']}','{$_POST['smb_DocLocal']}','{$_POST['smb_NIF']}','{$_POST['smb_AdmissionMotive']}','{$_POST['smb_Function']}')")==true) {
				$GetEdit = $GLOBALS['MYT']->db_array("SELECT smb_ID, name
					FROM systemoffice.staff_members 
					LEFT OUTER JOIN systemoffice.main_offices ON office_number = smb_Domain
					WHERE smb_Name = '{$_POST['smb_Name']}' ORDER BY smb_ID DESC LIMIT 0,1");
		$GLOBALS['MYT']->db_query("INSERT INTO systemoffice.timeclock_staffoff (tsv_Flag, tsv_Member, tsv_Domain, tsv_DateStart, tsv_DateEnd, tsv_Process, tsv_Observations, tsv_User)
		VALUES (1,{$GetEdit[1]['smb_ID']},'{$_POST['smb_Domain']}','{$_POST['smb_AdmissionDate']}','0000-00-00',{$PID},'',{$_SESSION[$SESSID]})");
			
				systemchange_hs('STAFFMEMBER_NEW',$GetEdit[1]['smb_ID']);
				echo '<script charset="utf-8" type="text/javascript">document.staffmember.smb_ID.value='.$GetEdit[1]['smb_ID'].';</script>';
				$RegID = $GetEdit[1]['smb_ID'];
				$TaskTime = $_POST['smb_AdmissionDate'];
		}	
	} else {
		$PID = 400;
		if($GLOBALS['MYT']->db_query("UPDATE systemoffice.staff_members 
				SET
				smb_Name = '{$_POST['smb_Name']}', 
				smb_CODE = {$_POST['smb_CODE']},
				smb_Birthdate = '{$_POST['smb_Birthdate']}',
				smb_AdmissionDate = '{$_POST['smb_AdmissionDate']}', 
				smb_CttEmail = '{$_POST['smb_CttEmail']}',
				smb_CttPhone = '{$_POST['smb_CttPhone']}',
				smb_CttExtention = '{$_POST['smb_CttExtention']}',
				smb_Domain = {$_POST['smb_Domain']},
				smb_CttAddress = '{$_POST['smb_CttAddress']}', 
				smb_DocID = {$_POST['smb_DocID']}, 
				smb_DocNumber = '{$_POST['smb_DocNumber']}', 
				smb_SSID = '{$_POST['smb_SSID']}', 
				smb_Nacionalidade = '{$_POST['smb_Nacionalidade']}', 
				smb_Civil = '{$_POST['smb_Civil']}', 
				smb_Dependentes = '{$_POST['smb_Dependentes']}', 
				smb_Habilitacoes = '{$_POST['smb_Habilitacoes']}', 
				smb_ContractType = '{$_POST['smb_ContractType']}', 
				smb_Wage = '{$_POST['smb_Wage']}', 
				smb_DocDate = '{$_POST['smb_DocDate']}', 
				smb_DocValid = '{$_POST['smb_DocValid']}', 
				smb_DocReceived = '{$_POST['smb_DocReceived']}', 
				smb_DocLocal = '{$_POST['smb_DocLocal']}', 
				smb_NIF = '{$_POST['smb_NIF']}', 
				smb_AdmissionMotive = '{$_POST['smb_AdmissionMotive']}', 
				smb_Function = '{$_POST['smb_Function']}'
				WHERE smb_ID = {$_POST['smb_ID']}")==true) {
				systemchange_hs('STAFFMEMBER_CHANGE',$_POST['smb_ID']);
		}	
	}
	echo '<div class="Confirm">Guardado.</div>';
	if ($RegID != 0) {
	include($GLOBALS['BIB'].'Pr_db/prc_modules/rh_comunication.php');
	}
